apiready = function() {
    seajs.use(['../../V', "../../api", "../../jquery", "../../app", "../../service"], function(V, $api, $, $app, service) {
      $app.ready();
        var vm = {
            el: '.container',
            data: {
                activeIndex: 0,
                tabTxt: ['商品', '店铺'],
                goodsList: '',
                shopList: '',
                goodspage: 1,
                storepage: 1,
                hvae_data: true
            },
            mounted: function() {
                this.init();
                this.downflash();
            },
            methods: {
                init: function() {
                    this.getgoodsdata(1);
                    this.getstoredata(1);
                },
                myCollectTab: function(et) {
                    var el = et.currentTarget;
                    var index = el.dataset.index;
                    var list = this.$refs.myCollectInfo.children;
                    for (var i = 0; i < list.length; i++) {
                        list[i].classList.remove("active");
                    }
                    list[+index].classList.add("active");
                    this.activeIndex = +index;
                },
                //加载商品收藏数据
                getgoodsdata: function(page) {
                    var that = this;
                    var unionId = $api.getStorage("shop_unionid");
                    $app.ajax(
                        service['getCollectGoodsList'], {
                            data: {
                                values: {
                                    unionid: unionId,
                                    page: page
                                }
                            }
                        },
                        function(res) {
                            console.log(JSON.stringify(res));
                            if (res.code == 0 && res.data.length > 0) {
                                if (page == 1) {
                                    that.goodsList = res.data;
                                } else {
                                    var goodsList = that.goodsList;
                                    goodsList.push(res.data);
                                    that.goodsList = goodsList;
                                }
                            }
                            that.$refs.myCollectGoodsNull.style.display = that.goodsList.length <= 0 ? 'block' : 'none';
                        }
                    );
                },
                //加载店铺收藏数据
                getstoredata: function(page) {
                    var that = this;
                    var unionId = $api.getStorage("shop_unionid");
                    $app.ajax(
                        service['getCollectStoreList'], {
                            data: {
                                values: {
                                    unionid: unionId,
                                    page: page
                                }
                            }
                        },
                        function(res) {
                            console.log(JSON.stringify(res));
                            if (res.code == 0 && res.data.length > 0) {
                                if (page == 1) {
                                    that.shopList = res.data;
                                } else {
                                    var shopList = that.shopList;
                                    shopList.push(res.data);
                                    that.shopList = shopList;
                                }
                            }
                            that.$refs.myCollectShopNull.style.display = that.shopList.length <= 0 ? 'block' : 'none';
                        }
                    );
                },
                //删除收藏数据
                deletecollect: function(fid, index) {
                    var that = this;
                    var unionId = $api.getStorage("shop_unionid");
                    var activeIndex = that.activeIndex;
                    var goodsList = that.goodsList;
                    var shopList = that.shopList;
                    $app.ajax(
                        service['cancelcollect'], {
                            data: {
                                values: {
                                    unionid: unionId,
                                    favorite_id: fid
                                }
                            }
                        },
                        function(res) {
                            console.log(JSON.stringify(res));
                            if (res.message == "成功") {
                                if (activeIndex == 0) {
                                    goodsList.splice(index, 1);
                                    that.goodsList = goodsList;
                                } else if (activeIndex == 1) {
                                    shopList.splice(index, 1);
                                    that.shopList = shopList;
                                }
                            }
                        }
                    );
                },
                //上拉到底加载更多
                downflash: function() {
                    var that = this;
                    api.addEventListener({
                        name: 'scrolltobottom',
                        extra: {
                            threshold: 0 //设置距离底部多少距离时触发，默认值为0，数字类型
                        }
                    }, function(ret, err) {
                        // alert('已滚动到底部');
                        var activeIndex = that.activeIndex;
                        if (activeIndex == 0) {
                            that.goodspage = that.goodspage + 1;
                            that.getgoodsdata(that.goodspage);
                        } else if (activeIndex == 1) {
                            that.storepage = that.storepage + 1;
                            that.getstoredata(that.storepage);
                        }
                    });
                },
                //--去商品详情
                goGoodsDetail: function(et) {
                    var name = et.target.tagName;
                    if (name == "A") {
                        return;
                    }
                    var goods_id = et.currentTarget.dataset.goodsid;
                    $app.openWin('buyGoods', {
                        goodsId: goods_id
                    });
                },
                //--去商品详情
                goShopIndex: function(et) {
                    var name = et.target.tagName;
                    if (name == "A") {
                        return;
                    }
                    var unionId = $api.getStorage("shop_unionid");
                    var shop_id = et.currentTarget.dataset.shopid;
                    var user_id = et.currentTarget.dataset.userid;
                    $app.ajax(service.getOtherShop, {
                        data: {
                            values: {
                                unionid: unionId,
                                other_user_id: user_id
                            }
                        }
                    }, function(res) {
                        //console.log(JSON.stringify(res));
                        if (res.code == 0) {
                            $app.openWin('singleShop', {
                                out_user_id: user_id
                            });
                        }
                    });
                }
            },
            created: function() {

            }
        };
        // var shopVue = new Vue(vm);
        var even = function() {

        };
        var newVue = new Vue(vm);
        even();

    })
}
